package com.ck.ips.controller;

import com.ck.common.model.DeviceGroup;
import com.ck.common.model.OperationResult;
import com.ck.core.annotation.LoginRequired;
import com.ck.core.annotation.ResourcePermissionRequired;
import com.ck.core.annotation.SysLog;
import com.ck.core.constant.ModuleConstant;
import com.ck.ips.service.DeviceGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @Description:  设备分组 controller
* @Author: hf
* @Date:    2019/5/7 16:31
* @Version: 1.0
*/
@LoginRequired
@RestController
@RequestMapping("/devicegroup")
public class DeviceGroupController extends BaseController {
	@Autowired
	private DeviceGroupService deviceGroupService;

	/**
	 *  保存终端分组
	 */
	@SysLog(module = ModuleConstant.MODULE_DEVICE_MNG)
	@PostMapping(value = "/save")
	public OperationResult saveDeviceGroup(DeviceGroup deviceGroup) {
		return deviceGroupService.saveDeviceGroup(deviceGroup);
	}

	/**
	 *  更新终端分组
	 */
	@SysLog(module = ModuleConstant.MODULE_DEVICE_MNG)
	@PostMapping(value = "update")
	public OperationResult updateDeviceGroup(DeviceGroup deviceGroup) {
		return deviceGroupService.updateDeviceGroup(deviceGroup);
	}

	/**
	 *  删除终端分组
	 */
	@SysLog(module = ModuleConstant.MODULE_DEVICE_MNG)
	@PostMapping(value = "/delete")
	public OperationResult deleteDeviceGroup(Long deviceGroupId) {
		return deviceGroupService.deleteDeviceGroup(deviceGroupId);
	}

	/**
	 * 生成分组树形列表
	 * 传入分辨率时为了在选点时，分组树计算的设备数据量跟设备列表查询出的数据量能够匹配上
	 * @return
	 */
	@PostMapping(value = "/tree")
	public Object deviceGroupTreeList(String resolvingPower) {
		return deviceGroupService.listAllDeviceGroupTree(resolvingPower);
	}

    /**
     * 生成某个角色的终端分组树形列表
     * @return
     */
    @PostMapping(value = "/roletree")
    public Object deviceGroupTreeByRole(Long roleId) {
        return deviceGroupService.deviceGroupTreeByRole(roleId);
    }

	/**
	 * 移动终端到分组
	 * @param deviceGroupId
	 * @param deviceCodes
	 * @return
	 */
	@ResourcePermissionRequired
	@PostMapping(value = "/move")
	public OperationResult moveDeviceGroup(Long deviceGroupId, String deviceCodes) {
		return deviceGroupService.moveDeviceGroup(deviceGroupId, deviceCodes);
	}

}
